package com.controller.app;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.apidoc.annotation.Api;
import com.apidoc.annotation.ApiAction;
import com.apidoc.annotation.ApiParam;
import com.apidoc.annotation.ApiReqParams;
import com.apidoc.annotation.ApiRespParams;
import com.apidoc.enumeration.DataType;
import com.apidoc.enumeration.Method;
import com.apidoc.enumeration.ParamType;
import com.controller.vo.CommisVo;
import com.dao.entity.Apply;
import com.service.IApplyService;
import com.service.ICommissionerService;
import com.service.IRCustCommisService;
import com.utils.commons.ResponseBean;
import com.utils.enums.ENUM_SUCESS;

@Api(name = "专员操作", order = 1, mapping = "/wx")
@RestController
@RequestMapping("/wx")
public class WxCommisController {
	
	@Autowired
	private ICommissionerService commissionerService;
	
	@Autowired
	private IRCustCommisService rCustCommisService;
	
	@Autowired
	private IApplyService applyService;
	
	@ApiAction(name = "获取个人信息", order = 1, mapping = "/getInfoCommis", method = Method.POST)
	@ApiReqParams(type = ParamType.URL_PARAM, value = {
			@ApiParam(name = "id", dataType = DataType.STRING, defaultValue = "", description = "id,2个属性2选一,必须"),
			@ApiParam(name = "openId", dataType = DataType.NUMBER, defaultValue = "", description = "openid,2个属性2选一,必须")
	})
	@ApiRespParams({
		@ApiParam(name = "status", dataType = DataType.NUMBER, defaultValue = "", description = "状态码"),
		@ApiParam(name = "data", dataType = DataType.OBJECT, defaultValue = "", description = "响应数据"),
		@ApiParam(name = "text", dataType = DataType.STRING, defaultValue = "", description = "提示信息")
	})
	@CrossOrigin(origins = "*")
	@RequestMapping(value = "/getInfoCommis", produces = "text/html;charset=UTF-8")
	@ResponseBody
	public String getInfoCommis(CommisVo commVo) {
		try {
			return ResponseBean.of(commissionerService.findCommis(commVo.toPo()), ENUM_SUCESS.SUCESS.value);
		} catch (Exception e) {
			return ResponseBean.of(ENUM_SUCESS.FAILED.value, e.getMessage());
		}
	}
	
	@ApiAction(name = "更新个人信息", order = 1, mapping = "/updateInfoCommis", method = Method.POST)
	@ApiReqParams(type = ParamType.URL_PARAM, value = {
			@ApiParam(name = "account", dataType = DataType.STRING, defaultValue = "", description = "帐号"),
			@ApiParam(name = "id", dataType = DataType.STRING, defaultValue = "", required = true, description = "id"),
            @ApiParam(name = "userName", dataType = DataType.STRING, defaultValue = "", description = "姓名"),
            @ApiParam(name = "idCard", dataType = DataType.STRING, defaultValue = "", description = "身份证"),
            @ApiParam(name = "sex", dataType = DataType.NUMBER, defaultValue = "", description = "0：女"),
            @ApiParam(name = "openId", dataType = DataType.NUMBER, defaultValue = "", description = "openid")
    })
    @ApiRespParams({
            @ApiParam(name = "status", dataType = DataType.NUMBER, defaultValue = "", description = "状态码"),
            @ApiParam(name = "data", dataType = DataType.OBJECT, defaultValue = "", description = "响应数据"),
            @ApiParam(name = "text", dataType = DataType.STRING, defaultValue = "", description = "提示信息")
    })
	@CrossOrigin(origins = "*")
	@RequestMapping(value = "/updateInfoCommis", produces = "text/html;charset=UTF-8")
	@ResponseBody
	public String updateInfoCommis(CommisVo commVo) {
		try {
			return ResponseBean.of(commissionerService.saveUser(commVo.toPo()), ENUM_SUCESS.SUCESS.value);
		} catch (Exception e) {
			return ResponseBean.of(ENUM_SUCESS.FAILED.value, e.getMessage());
		}
	}
	
	@ApiAction(name = "我的客户列表", order = 2, mapping = "/getMyCustomers", method = Method.POST)
	@ApiReqParams(type = ParamType.URL_PARAM, value = {
			@ApiParam(name = "commisId", dataType = DataType.NUMBER, defaultValue = "", required = true, description = "专员id(我)"),
			@ApiParam(name = "page", dataType = DataType.NUMBER, defaultValue = "", description = "页数"),
			@ApiParam(name = "size", dataType = DataType.NUMBER, defaultValue = "", description = "页大小"),
    })
    @ApiRespParams({
	    	@ApiParam(name = "status", dataType = DataType.NUMBER, defaultValue = "", description = "状态码"),
	        @ApiParam(name = "data", dataType = DataType.OBJECT, defaultValue = "", description = "响应数据", object="pageUtils"),
	        @ApiParam(name = "size", dataType = DataType.NUMBER, defaultValue = "", description = "页大小", belongTo="pageUtils"),
	        @ApiParam(name = "totalPages", dataType = DataType.NUMBER, defaultValue = "", description = "总页数", belongTo="pageUtils"),
	        @ApiParam(name = "totalElements", dataType = DataType.NUMBER, defaultValue = "", description = "总数", belongTo="pageUtils"),
	        @ApiParam(name = "content", dataType = DataType.OBJECT, defaultValue = "", description = "列表数据", belongTo="pageUtils", object="TempStaff"),
	        
	        @ApiParam(name = "id", dataType = DataType.NUMBER, defaultValue = "", description = "id", belongTo="TempStaff"),
	        @ApiParam(name = "userName", dataType = DataType.NUMBER, defaultValue = "", description = "姓名", belongTo="TempStaff"),
	        @ApiParam(name = "idCard", dataType = DataType.NUMBER, defaultValue = "", description = "身份证", belongTo="TempStaff"),
	        @ApiParam(name = "sex", dataType = DataType.NUMBER, defaultValue = "", description = "性别，女0,男1", belongTo="TempStaff"),
	        @ApiParam(name = "text", dataType = DataType.STRING, defaultValue = "", description = "提示信息")
    })
	@CrossOrigin(origins = "*")
	@RequestMapping(value = "/getMyCustomers", produces = "text/html;charset=UTF-8")
	@ResponseBody
	public String getMyCustomers(Long commisId, Integer page, Integer size) {
		try {
			return ResponseBean.of(rCustCommisService.getMyCustomers(commisId, page, size), ENUM_SUCESS.SUCESS.value);
		} catch (Exception e) {
			return ResponseBean.of(ENUM_SUCESS.FAILED.value, e.getMessage());
		}
	}
	
	@ApiAction(name = "（我的客户的）申请列表", order = 3, mapping = "/getCustomerApplys", method = Method.POST)
	@ApiReqParams(type = ParamType.URL_PARAM, value = {
			@ApiParam(name = "commisId", dataType = DataType.NUMBER, defaultValue = "", required = true, description = "专员id"),
			@ApiParam(name = "customerId", dataType = DataType.NUMBER, defaultValue = "", description = "客户id"),
			@ApiParam(name = "isComplete", dataType = DataType.NUMBER, defaultValue = "0", description = "是否完成的贷款，0：未完成"),
			@ApiParam(name = "page", dataType = DataType.NUMBER, defaultValue = "", description = "页数"),
			@ApiParam(name = "size", dataType = DataType.NUMBER, defaultValue = "", description = "页大小"),
    })
    @ApiRespParams({
	    	@ApiParam(name = "status", dataType = DataType.NUMBER, defaultValue = "", description = "状态码"),
	        @ApiParam(name = "data", dataType = DataType.OBJECT, defaultValue = "", description = "响应数据", object="pageUtils"),
	        @ApiParam(name = "size", dataType = DataType.NUMBER, defaultValue = "", description = "页大小", belongTo="pageUtils"),
	        @ApiParam(name = "totalPages", dataType = DataType.NUMBER, defaultValue = "", description = "总页数", belongTo="pageUtils"),
	        @ApiParam(name = "totalElements", dataType = DataType.NUMBER, defaultValue = "", description = "总数", belongTo="pageUtils"),
	        @ApiParam(name = "content", dataType = DataType.OBJECT, defaultValue = "", description = "列表数据", belongTo="pageUtils", object="TempStaff"),
	        
	        @ApiParam(name = "id", dataType = DataType.NUMBER, defaultValue = "", description = "申请id", belongTo="TempStaff"),
	        @ApiParam(name = "customerId", dataType = DataType.NUMBER, defaultValue = "", description = "客户id", belongTo="TempStaff"),
	        @ApiParam(name = "customerName", dataType = DataType.STRING, defaultValue = "", description = "客户姓名", belongTo="TempStaff"),
	        @ApiParam(name = "idCard", dataType = DataType.STRING, defaultValue = "", description = "身份证", belongTo="TempStaff"),
	        @ApiParam(name = "sex", dataType = DataType.NUMBER, defaultValue = "", description = "性别，女0,男1", belongTo="TempStaff"),
	        @ApiParam(name = "age", dataType = DataType.NUMBER, defaultValue = "", description = "年龄", belongTo="TempStaff"),
	        @ApiParam(name = "loanAge", dataType = DataType.NUMBER, defaultValue = "", description = "贷款年限", belongTo="TempStaff"),
	        @ApiParam(name = "houseAge", dataType = DataType.NUMBER, defaultValue = "", description = "房龄", belongTo="TempStaff"),
	        @ApiParam(name = "landType", dataType = DataType.STRING, defaultValue = "", description = "土地类型", belongTo="TempStaff"),
	        @ApiParam(name = "isEconomize", dataType = DataType.NUMBER, defaultValue = "", description = "是否经济适用房 1是0否", belongTo="TempStaff"),
	        @ApiParam(name = "isComplete", dataType = DataType.NUMBER, defaultValue = "", description = "是否完成 1是0否", belongTo="TempStaff"),
	        @ApiParam(name = "text", dataType = DataType.STRING, defaultValue = "", description = "提示信息")
    })
	@CrossOrigin(origins = "*")
	@RequestMapping(value = "/getCustomerApplys", produces = "text/html;charset=UTF-8")
	@ResponseBody
	public String getCustomerApplys(Apply Apply, Integer page, Integer size) {
		try {
			return ResponseBean.of(applyService.getApplys(Apply, page, size), ENUM_SUCESS.SUCESS.value);
		} catch (Exception e) {
			return ResponseBean.of(ENUM_SUCESS.FAILED.value, e.getMessage());
		}
	}
	
	@ApiAction(name = "完成申请", order = 3, mapping = "/completeApply", method = Method.POST)
	@ApiReqParams(type = ParamType.URL_PARAM, value = {
			@ApiParam(name = "applyId", dataType = DataType.NUMBER, defaultValue = "申请id", required = true, description = "客户id"),
    })
    @ApiRespParams({
	    	@ApiParam(name = "status", dataType = DataType.NUMBER, defaultValue = "", description = "状态码"),
	        @ApiParam(name = "data", dataType = DataType.OBJECT, defaultValue = "", description = "响应数据"),
	        @ApiParam(name = "text", dataType = DataType.STRING, defaultValue = "", description = "提示信息")
    })
	@CrossOrigin(origins = "*")
	@RequestMapping(value = "/completeApply", produces = "text/html;charset=UTF-8")
	@ResponseBody
	public String completeApply(Long applyId) {
		try {
			applyService.completeApply(applyId);
		} catch (Exception e) {
			return ResponseBean.of(ENUM_SUCESS.FAILED.value, e.getMessage());
		}
		return ResponseBean.of(ENUM_SUCESS.SUCESS.value);
	}
}
